
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLShortField.java 187 2009-11-12 18:27:01Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import org.dellroad.sidekar.ShortField;

/**
 * Container for a {@link ShortField}'s value during the Sidekar XML import/export process.
 */
class XMLShortField extends XMLAtomicField<Short> {

    private short value;

    // Used during unmarshalling
    private XMLShortField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLShortField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLShortField(String name, short value) {
        super(name);
        this.value = value;
    }

    // Used during unmarshalling
    @Override
    public Short getObjectValue() {
        return this.value;
    }

    // Used during marshalling
    @Override
    public boolean hasDefaultValue() {
        return this.value == (short)0;
    }

    // Used during unmarshalling
    public static XMLShortField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLShortField((XMLItem)obj) : new XMLShortField((XMLField)obj);
    }
}

